package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.GameManager;
import com.juyu.miliao.api.domain.vo.GameManagerVO;
import com.juyu.miliao.api.domain.vo.GameRankingForSortVo;
import com.juyu.miliao.api.domain.vo.GameRankingListLogVO;
import com.juyu.miliao.api.domain.vo.GameRankingVo;
import com.juyu.miliao.api.service.GameAllRankingListService;
import com.juyu.miliao.common.domain.Subject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @Auther: 卜加超
 * @Date: 2019/8/20 14:12
 * @Description:
 */
@RestController
@RequestMapping("gameRanking")
@Slf4j
public class GameAllRankingListController {

    @Resource
    private GameAllRankingListService gameAllRankingListService;

    /**
     * 游戏列表
     * @return
     */
    @GetMapping("/list")
    public List<GameManagerVO> getGameList(){
        return gameAllRankingListService.getGameList();
    }

    /**
     * 游戏排行榜
     * @param type 1:当天 2：昨天 3:本周 4:上周
     * @return
     */
    @GetMapping("/list/{type}")
    public List<GameRankingVo> getGameAllRankingList(@PathVariable("type")int type){
        return gameAllRankingListService.getGameAllRankingList(type, LocalDate.now());
    }

    /**
     * 排行榜之我的排名
     */
    @GetMapping("/sort/{type}")
    public GameRankingForSortVo getMySort(@PathVariable("type")int type, Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return gameAllRankingListService.findMySort(type,subject.getId());
    }

    /**
     *
     */
    @GetMapping("/sort")
    public GameRankingForSortVo getMySortByMyProfit(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return gameAllRankingListService.findMySortByMyProfit(subject.getId());
    }

    /**
     * 往期回顾
     * @param token
     * @return
     */
    @GetMapping("/rewardList")
    public List<GameRankingListLogVO> getGameRankingListLog(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
        return gameAllRankingListService.getGameRankingListLog(subject.getId());
    }


}
